

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>CephFS 支持的能力 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/sphinx_highlight.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="CephFS API （编程接口）" href="../api/" />
    <link rel="prev" title="Journaler （日志记录器）" href="../journaler/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../">Ceph 文件系统</a></li>
      <li class="breadcrumb-item active">CephFS 支持的能力</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../../_sources/cephfs/capabilities.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../" class="icon icon-home"> Ceph
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">Ceph 文件系统</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../#cephfs">CephFS 入门</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id4">管理</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id5">挂载 CephFS</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id6">CephFS 内幕</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../#id7">故障排除和灾难恢复</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../eviction/"> 驱逐客户端</a></li>
<li class="toctree-l3"><a class="reference internal" href="../scrub/"> 洗刷</a></li>
<li class="toctree-l3"><a class="reference internal" href="../full/"> 文件系统占满的处理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../disaster-recovery-experts/"> 元数据修复</a></li>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/"> 故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../disaster-recovery/"> 灾难恢复</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cephfs-journal-tool/"> cephfs-journal-tool</a></li>
<li class="toctree-l3"><a class="reference internal" href="../recover-fs-after-mon-store-loss/"> 监视器存储丢失后恢复文件系统</a></li>
<li class="toctree-l3 current"><a class="reference internal" href="../#id8">开发者指南</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="../journaler/"> Journaler 配置</a></li>
<li class="toctree-l4 current"><a class="current reference internal" href="#"> 客户端的能力</a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/"> Java 和 Python 捆绑库</a></li>
<li class="toctree-l4"><a class="reference internal" href="../mantle/"> Mantle</a></li>
<li class="toctree-l4"><a class="reference internal" href="../metrics/">指标</a></li>
<li class="toctree-l4"><a class="reference internal" href="../metrics/#id3">查看指标</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../#id9">更多细节</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../monitoring/">监控概览</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../hardware-monitoring/">硬件监控</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <section id="cephfs">
<h1>CephFS 支持的能力<a class="headerlink" href="#cephfs" title="Permalink to this heading"></a></h1>
<p>一个客户端想要操作索引节点时，它会向 MDS 发起多种查询，
MDS 会授予此客户端一系列<em>能力（ capabilities ）</em>，有了这些能力，客户端就有权限操作索引节点了。与其它网络文件系统（如 NFS 或 SMB ）相比，
一个主要的区别在于这些授予的能力非常粗糙，
而且它允许多个客户端同时持有同一索引节点的不同能力。</p>
<section id="id1">
<h2>能力的种类<a class="headerlink" href="#id1" title="Permalink to this heading"></a></h2>
<p>有几种“常规”能力位，下面的表示这个能力位授予它哪种能力。</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cm">/* generic cap bits */</span>
<span class="cp">#define CEPH_CAP_GSHARED     1  </span><span class="cm">/* (metadata) client can reads (s) */</span>
<span class="cp">#define CEPH_CAP_GEXCL       2  </span><span class="cm">/* (metadata) client can read and update (x) */</span>
<span class="cp">#define CEPH_CAP_GCACHE      4  </span><span class="cm">/* (file) client can cache reads (c) */</span>
<span class="cp">#define CEPH_CAP_GRD         8  </span><span class="cm">/* (file) client can read (r) */</span>
<span class="cp">#define CEPH_CAP_GWR        16  </span><span class="cm">/* (file) client can write (w) */</span>
<span class="cp">#define CEPH_CAP_GBUFFER    32  </span><span class="cm">/* (file) client can buffer writes (b) */</span>
<span class="cp">#define CEPH_CAP_GWREXTEND  64  </span><span class="cm">/* (file) client can extend EOF (a) */</span>
<span class="cp">#define CEPH_CAP_GLAZYIO   128  </span><span class="cm">/* (file) client can perform lazy io (l) */</span>
</pre></div>
</div>
<p>然后，给这些数字做一定数量的位移。这些表示能力是要授权给 inode 的数据或元数据的一部分：</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cm">/* per-lock shift */</span>
<span class="cp">#define CEPH_CAP_SAUTH      2 </span><span class="cm">/* A */</span>
<span class="cp">#define CEPH_CAP_SLINK      4 </span><span class="cm">/* L */</span>
<span class="cp">#define CEPH_CAP_SXATTR     6 </span><span class="cm">/* X */</span>
<span class="cp">#define CEPH_CAP_SFILE      8 </span><span class="cm">/* F */</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>译者注：下面这段没完全理解，也许翻译的有问题，先附上原文。</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">译文<span class="colon">:</span></dt>
<dd class="field-odd"><p>然而，以前只有某些常规能力授予了其中的一些“位移”，特别是，只有
FILE 位移多于前两位。</p>
</dd>
<dt class="field-even">原文<span class="colon">:</span></dt>
<dd class="field-even"><p>Only certain generic cap types are ever granted for some of those “shifts”, however. In particular, only the FILE shift ever has more than the first two bits.</p>
</dd>
</dl>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">|</span> <span class="n">AUTH</span> <span class="o">|</span> <span class="n">LINK</span> <span class="o">|</span> <span class="n">XATTR</span> <span class="o">|</span> <span class="n">FILE</span>
<span class="mi">2</span>      <span class="mi">4</span>      <span class="mi">6</span>       <span class="mi">8</span>
</pre></div>
</div>
<p>从以上定义我们得到几个常数，它是用各个位值移位到相应的位（用变量表示）生成的：</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cp">#define CEPH_CAP_AUTH_SHARED  (CEPH_CAP_GSHARED  &lt;&lt; CEPH_CAP_SAUTH)</span>
</pre></div>
</div>
<p>然后，这些位就可以通过或操作产生位掩码（ bitmask ），用以表示一系列能力。</p>
<p>有一个例外的：</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cp">#define CEPH_CAP_PIN  1  </span><span class="cm">/* no specific capabilities beyond the pin */</span>
</pre></div>
</div>
<p>pin 只是把 inode 插入内存，不授予任何能力。</p>
<p>图形化就是：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">+---+---+---+---+---+---+---+---+</span>
<span class="o">|</span> <span class="n">p</span> <span class="o">|</span> <span class="n">_</span> <span class="o">|</span><span class="n">As</span>   <span class="n">x</span> <span class="o">|</span><span class="n">Ls</span>   <span class="n">x</span> <span class="o">|</span><span class="n">Xs</span>   <span class="n">x</span> <span class="o">|</span>
<span class="o">+---+---+---+---+---+---+---+---+</span>
<span class="o">|</span><span class="n">Fs</span>   <span class="n">x</span>   <span class="n">c</span>   <span class="n">r</span>   <span class="n">w</span>   <span class="n">b</span>   <span class="n">a</span>   <span class="n">l</span> <span class="o">|</span>
<span class="o">+---+---+---+---+---+---+---+---+</span>
</pre></div>
</div>
<p>当前尚未使用第二个 bit 。</p>
</section>
<section id="cap">
<h2>各个 cap 授予的能力<a class="headerlink" href="#cap" title="Permalink to this heading"></a></h2>
<p>这就解释了能力是如何授予的（和通讯的），重要的位是它允许客户端干什么：</p>
<ul class="simple">
<li><p><strong>PIN</strong>: 只是把 inode 插入内存。这足以让客户端取得 inode 号，
还有其它的不可变信息，如设备 inode 的主、次设备号、或符号链接内容。</p></li>
<li><p><strong>AUTH</strong>: 授予能力以获取与认证相关的元数据，
特别是所有者、组和权限位。需要注意的是，
完整的权限检查也许还要获取 ACL ，它是存在扩展属性（ xattrs ）里的。</p></li>
<li><p><strong>LINK</strong>: inode 的链接计数。</p></li>
<li><p><strong>XATTR</strong>: 访问或修改扩展属性的能力。另外，由于 ACL 定义存在扩展属性里，
有时候检查权限还需访问它们。</p></li>
<li><p><strong>FILE</strong>: 这是个大头，允许客户端访问和修改数据。
也涵盖了与文件数据相关的元数据——
特别是尺寸、 mtime 、 atime 、 ctime 。</p></li>
</ul>
</section>
<section id="id2">
<h2>简写<a class="headerlink" href="#id2" title="Permalink to this heading"></a></h2>
<p>需要注意的是，客户端日志里会紧凑地表达各个能力，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">pAsLsXsFs</span>
</pre></div>
</div>
<p>其中， p 表示 pin ，各大写字母对应位移值，而位移值后面的小写字母是真正赋予此位置的的能力。</p>
</section>
<section id="id3">
<h2>锁状态和能力之间的关系<a class="headerlink" href="#id3" title="Permalink to this heading"></a></h2>
<p>在 MDS 中，每个节点有四种不同的锁，分别是 simplelock 、
scatterlock 、 filelock 和 locallock 。每种锁都有几种不同的锁状态，
MDS 会根据锁状态向客户端发放能力。</p>
<p>在每种状态下， MDS Locker 都会尝试向客户端发布所有允许的能力，
即使有些能力是客户端不需要或不想要的，
因为某些情况下，预先发放能力可以减少延时。</p>
<p>如果只有一个客户端，它通常是所有节点的独行客户端（ loner client ）。
而在有多个客户端的情况下， MDS 会尝试根据客户端（需要 | 想要）的能力
为每个节点计算出一个独行客户端，
但通常会失败。独行客户端将始终获得所有能力。</p>
<p>filelock 会控制文件的、部分元数据的、和文件内容的访问权限。
元数据包括 <strong>mtime</strong> 、 <strong>atime</strong> 、 <strong>size</strong> 等。</p>
<ul>
<li><p><strong>Fs</strong>: 客户端一旦拥有它，其他所有客户端的 <strong>Fw</strong> 都将被拒绝。</p></li>
<li><p><strong>Fx</strong>: 只有独行客户端才可拥有此能力。
一旦锁状态转换为 LOCK_EXCL ，独行客户端就会被授予此能力，
以及其他所有除 <strong>Fl</strong> 以外的能力.</p></li>
<li><p><strong>Fr</strong>: 一旦某个客户端拥有了它，说明其他所有客户端的 <strong>Fb</strong> 能力都已经被撤销。</p>
<p>如果客户端只要求读取文件，锁状态将直接转为 LOCK_SYNC 稳定状态。
所有客户端都可以从权威 MDS 获得 <strong>Fscrl</strong> 能力，
从副本 MDS 获得 <strong>Fscr</strong> 能力。</p>
<p>如果多个客户端读出和写入同一个文件，
那么锁状态将最终转换到 LOCK_MIX 稳定状态，
所有客户端都可以获得权威 MDS 的 <strong>Frwl</strong> 能力和副本 MDS 的 <strong>Fr</strong> 能力。
<strong>Fcb</strong> 能力不会授予所有客户端，客户端们将做同步读/写操作。</p>
</li>
<li><p><strong>Fw</strong>: 如果没有独行客户端，并且一旦某个客户端获得此能力，
<strong>Fsxcb</strong> 能力将不能授予其他客户端。</p>
<p>如果多个客户端读出和写入同一个文件，
那么锁状态将最终转换到 LOCK_MIX 稳定状态，
所有客户端都可以获取权威 MDS 的 <strong>Frwl</strong> 能力和来自副本 MDS 的 <strong>Fr</strong> 能力。
<strong>Fcb</strong> 能力不会授予所有客户端，
客户端们将做同步读/写操作。</p>
</li>
<li><p><strong>Fc</strong>: 该能力意味着客户端们可以缓存文件读出操作，
应与 <strong>Fr</strong> 能力一起发放，
只有在这种用例中才有意义。</p>
<p>实际上，在一些稳定或临时过渡状态下，
即使没有授予 <strong>Fr</strong> 能力，也会允许使用 <strong>Fc</strong> ，
因为这样可以避免强制客户端丢弃完整缓存，
例如在简单的文件大小扩展或截断用例中。</p>
</li>
<li><p><strong>Fb</strong>: 该能力意味着客户端可以缓冲文件写入操作，
应与 <strong>Fw</strong> 能力一起发放，
只有在这种情境下才有意义。</p>
<p>实际上，在某些稳定或临时过渡状态下，
即使不授予 <strong>Fw</strong> 能力，也会保留 <strong>Fc</strong> 能力，
因为这样可以避免强制客户端丢弃脏缓冲区，
例如在简单的文件大小扩展或截断用例中。</p>
</li>
<li><p><strong>Fl</strong>: 这个能力意味着客户端可以施行懒惰 IO 。
LazyIO 放宽了 POSIX 语义。即使一个文件同时被多个客户端上的多个应用程序打开，也允许缓冲读/写。
应用程序它们自行负责管理缓存一致性。</p></li>
</ul>
</section>
</section>



<div id="support-the-ceph-foundation" class="admonition note">
  <p class="first admonition-title">Brought to you by the Ceph Foundation</p>
  <p class="last">The Ceph Documentation is a community resource funded and hosted by the non-profit <a href="https://ceph.io/en/foundation/">Ceph Foundation</a>. If you would like to support this and our other efforts, please consider <a href="https://ceph.io/en/foundation/join/">joining now</a>.</p>
</div>


           </div>
           
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="../journaler/" class="btn btn-neutral float-left" title="Journaler （日志记录器）" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../api/" class="btn btn-neutral float-right" title="CephFS API （编程接口）" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).</p>
  </div>

   

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>